package cn.shuangbofu.nocturne.server;

import cn.shuangbofu.nocturne.channel.RequestChannel;
import cn.shuangbofu.nocturne.netty.event.Event;
import cn.shuangbofu.nocturne.netty.server.NettyServer;
import cn.shuangbofu.nocturne.server.dispatcher.MockDispatcher;
import cn.shuangbofu.nocturne.server.service.ExecutorStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by shuangbofu on 2020/7/23 10:26
 */
public class Server {

    private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);

    public static void main(String[] args) throws InterruptedException {
        int port = Integer.parseInt(args[0]);
        new NettyServer()
                .listen(Event.UNREGISTER, Server::executorDisconnect)
                .onReceive(new ServerHandlerSet())
                .start(port);
        // 模拟任务分发
        new MockDispatcher().start();
        LOGGER.info("服务启动完毕！");
    }

    public static void executorDisconnect(RequestChannel channel) {
        LOGGER.info("executor断开连接，server做一些操作！");
        ExecutorStore.INSTANCE.unregister(channel);
    }
}
